package org.jeecg.basic.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.basic.entity.MesLineOpCfg;
import org.jeecg.basic.service.IMesLineOpCfgService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 工序配置
 * @Author: LiCY
 * @Date: 2023-06-17
 * @Version: V1.0
 */
@Api(tags = "工序配置")
@RestController
@RequestMapping("/basic/mesLineOpCfg")
@Slf4j
public class MesLineOpCfgController extends JeecgController<MesLineOpCfg, IMesLineOpCfgService> {
    @Autowired
    private IMesLineOpCfgService mesLineOpCfgService;

    /**
     * 分页列表查询666
     *
     * @param mesLineOpCfg
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "工序配置-分页列表查询")
    @ApiOperation(value = "工序配置-分页列表查询", notes = "工序配置-分页列表查询")
    @GetMapping(value = "/list")
    @DS("#header.his")
    public Result<IPage<MesLineOpCfg>> queryPageList(MesLineOpCfg mesLineOpCfg,
                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                     HttpServletRequest req) {
        QueryWrapper<MesLineOpCfg> queryWrapper = QueryGenerator.initQueryWrapper(mesLineOpCfg, req.getParameterMap());
        queryWrapper.orderByAsc("sequence");
        Page<MesLineOpCfg> page = new Page<MesLineOpCfg>(pageNo, pageSize);
        IPage<MesLineOpCfg> pageList = mesLineOpCfgService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param mesLineOpCfg
     * @return
     */
    @AutoLog(value = "工序配置-添加")
    @ApiOperation(value = "工序配置-添加", notes = "工序配置-添加")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_line_op_cfg:add")
    @PostMapping(value = "/add")
    @DS("#header.line")
    public Result<String> add(@RequestBody MesLineOpCfg mesLineOpCfg) {
        mesLineOpCfgService.save(mesLineOpCfg);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param mesLineOpCfg
     * @return
     */
    @AutoLog(value = "工序配置-编辑")
    @ApiOperation(value = "工序配置-编辑", notes = "工序配置-编辑")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_line_op_cfg:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    @DS("#header.line")
    public Result<String> edit(@RequestBody MesLineOpCfg mesLineOpCfg) {
        mesLineOpCfgService.updateByMultiId(mesLineOpCfg);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过选中对象删除
     *
     * @param mesLineOpCfg
     * @return
     */
    @AutoLog(value = "工序配置-通过id删除")
    @ApiOperation(value = "工序配置-通过id删除", notes = "工序配置-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_line_op_cfg:delete")
    @RequestMapping(value = "/delete")
    public Result<String> delete(@RequestBody MesLineOpCfg mesLineOpCfg) {
        mesLineOpCfgService.deleteByMultiId(mesLineOpCfg);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param list
     * @return
     */
    @AutoLog(value = "工序配置-批量删除")
    @ApiOperation(value = "工序配置-批量删除", notes = "工序配置-批量删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_line_op_cfg:deleteBatch")
    @RequestMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestBody List<MesLineOpCfg> list) {
        list.forEach(item -> {
            mesLineOpCfgService.deleteByMultiId(item);
        });
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过line查询
     *
     * @return
     */
    //@AutoLog(value = "工序配置-通过id查询")
    @ApiOperation(value = "工序配置-通过id查询", notes = "工序配置-通过id查询")
    @GetMapping(value = "/opSelect")
    @DS("#header.his")
    public Result<List<MesLineOpCfg>> opSelect() {
        List<MesLineOpCfg> opSelects = mesLineOpCfgService.list();
        if (opSelects.isEmpty()) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(opSelects);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param mesLineOpCfg
     */
    //@RequiresPermissions("org.jeecg.modules.demo:mes_line_op_cfg:exportXls")
    @RequestMapping(value = "/exportXls")
    @DS("#header.his")
    public ModelAndView exportXls(HttpServletRequest request, MesLineOpCfg mesLineOpCfg) {
        return super.exportXls(request, mesLineOpCfg, MesLineOpCfg.class, "工序配置");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("mes_line_op_cfg:importExcel")
    @DS("#header.line")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, MesLineOpCfg.class);
    }

}
